﻿using TMPro;
using UnityEngine;
using Utils;

public class PanelController
{
    public PlayerPanel playerPanel;
    public WeaponPanel weaponPanel;
    public LoadPanel loadPanel;
    public PhonePanel phonePanel;
    public BossPanel bossPanel;

    public void LoadLoginPanel()
    {
        UITool.InstantiatePrefabUI(PrefabRoot.LoginPanel.Path, PrefabRoot.LoginPanel.Name);
    }

    public LoginPanel GetLoginPanel()
    {
        return UITool.InstantiatePrefabUI(PrefabRoot.LoginPanel.Path, PrefabRoot.LoginPanel.Name)
            .GetComponent<LoginPanel>();
    }

    public void LoadPausePanel()
    {
        Time.timeScale = 0;
        GameController.Instance().FSM.CurGameState = GameState.Pausing;
        UITool.InstantiatePrefabUI(PrefabRoot.PausePanel.Path, PrefabRoot.PausePanel.Name);
    }

    public void LoadPlayerPanel()
    {
        playerPanel = UITool.InstantiatePrefabUI(PrefabRoot.PlayerPanel.Path, PrefabRoot.PlayerPanel.Name)
            .GetComponent<PlayerPanel>();
    }

    public void LoadWeaponPanel(string name, string atk, string mp)
    {
        weaponPanel = UITool.InstantiatePrefabUI(PrefabRoot.WeaponPanel.Path, PrefabRoot.WeaponPanel.Name)
            .GetComponent<WeaponPanel>();
        weaponPanel.SetValue(name, atk, mp);
    }

    public void LoadGameOverPanel()
    {
        Time.timeScale = 0;
        GameController.Instance().FSM.CurGameState = GameState.Over;
        UITool.InstantiatePrefabUI(PrefabRoot.GameOverPanel.Path, PrefabRoot.GameOverPanel.Name);
    }

    public void LoadPhonePanel()
    {
        phonePanel = UITool.InstantiatePrefabUI(PrefabRoot.PhonePanel.Path, PrefabRoot.PhonePanel.Name)
            .GetComponent<PhonePanel>();
    }

    public void LoadCharacterPanel()
    {
        UITool.InstantiatePrefabUI(PrefabRoot.CharacterPanel.Path, PrefabRoot.CharacterPanel.Name);
    }

    public void LoadLoadingPanel()
    {
        UITool.InstantiatePrefabUI(PrefabRoot.LoadPanel.Path, PrefabRoot.LoadPanel.Name);
    }

    public GameObject LoadTipsPanel(string content)
    {
        GameObject go = UITool.InstantiatePrefabUI(PrefabRoot.TipsPanel.Path, PrefabRoot.TipsPanel.Name);
        go.GetComponentInChildren<TextMeshProUGUI>().text = content;
        return go;
    }

    public GameObject LoadBossPanel(Monster monster)
    {
        GameObject go = UITool.InstantiatePrefabUI(PrefabRoot.BossPanel.Path, PrefabRoot.BossPanel.Name);
        go.GetComponent<BossPanel>().monster = monster;
        go.SetActive(true);
        bossPanel = go.GetComponent<BossPanel>();
        return go;
    }

    public void LoadPlayerDataPanel(int gemNum, int killed, int addGem, int addKill)
    {
        PlayerDataPanel playerDataPanel = UITool.InstantiatePrefabUI(PrefabRoot.PlayerDataPanel.Path, PrefabRoot.PlayerDataPanel.Name).GetComponent<PlayerDataPanel>();
        playerDataPanel.gemNum = gemNum;
        playerDataPanel.killed = killed;
        playerDataPanel.addGem = addGem;
        playerDataPanel.addKill = addKill;
        playerDataPanel.enabled = true;
    }

    public void LoadSettingPanel()
    {
        UITool.InstantiatePrefabUI(PrefabRoot.SettingPanel.Path, PrefabRoot.SettingPanel.Name);
    }

    public void RemoveBossPanel()
    {
        if (bossPanel)
        {
            Object.Destroy(bossPanel.gameObject);
            bossPanel = null; 
        }
    }

    public void RemoveWeaponPanel()
    {
        if (weaponPanel)
        {
            weaponPanel.UnLoad();
            weaponPanel = null;
        }
    }
}